<?php

class tools_helper
{
    /**
     * get excel column name by column num
     *
     * @param $column_num
     * @return string
     *
     * @example
     *
     * 1 => A
     * 20 =>
     */
    public static function excel_column_encode($column_num) {
        $S = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $SL = strlen($S);
        $str = '';
        $sum = 0;
        do {
            $i = $column_num % $SL;
            $str = $S[$i - ($sum > 0 ? 1 : 0)] . $str;
            $column_num = ($column_num - $i) / $SL;
            $sum++;
        } while ($column_num > 0);
        return $str;
    }
}